/**
 * ImageListModelImpl.java Create on 2012-8-1     
*      
* Copyright (c) 2012-8-1 by yiming     
*      
* @author <a href="alenzhangym@hotmail.com">Yiming</a>     
* @version 1.0 
 */
package com.yimi.content;

import com.yimi.service.BaseImageItem;
import com.yimi.service.ImageList;

import java.util.ArrayList;
import java.util.List;

/**
 * TOD 
 *      
 * @author Yiming
 * @version 1.0 
 */
public class ImageListModelImpl implements ImageListModel {
    private List<BaseImageItem> imageList;
    
    public ImageListModelImpl(){
        imageList = new ArrayList();
    }
    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#getSize()
     */
    @Override
    public int getSize() { 
        return imageList.size();
    }

    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#getImageItem(int)
     */
    @Override
    public BaseImageItem getImageItem(int position) {
        // TODO Auto-generated method stub
        return imageList.get(position);
    }

    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#addImageItem(com.yimi.service.ImageItem)
     */
    @Override
    public void addImageItem(BaseImageItem imageItem) {
        // TODO Auto-generated method stub
        imageList.add(imageItem);
    }

    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#removeImageItem(com.yimi.service.ImageItem)
     */
    @Override
    public void removeImageItem(BaseImageItem imageItem) {
        imageList.remove(imageItem);
    }
    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#addImageList(com.yimi.service.ImageList)
     */
    @Override
    public void addImageList(ImageList list) {
        List srcImageList = list.getImageList();
        imageList.addAll(0, srcImageList);
    }
    /* (non-Javadoc)
     * @see com.yimi.content.ImageListModel#updateItem(com.yimi.service.BaseImageItem)
     */
    @Override
    public void updateItem(BaseImageItem previewItem) {
        for(int i=0;i<imageList.size();i++){
            BaseImageItem baseItem =     imageList.get(i);
            if(baseItem.getPreviewURL()!=null){
                if(baseItem.getPreviewURL().equals(previewItem.getPreviewURL())){
                    imageList.remove(i);
                    imageList.add(i, previewItem);
                }
            }
        }
    }

}
